<template>
	<view class="contenter">
		<view class="block__title">基本信息</view>
		<view class="cu-form-group">
			<view class="title">姓名</view>
			<input placeholder="请输入姓名" v-model="name"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">成员身份类型</view>
			<picker bindchange="PickerChange" :value="repairScopeIndex" :range="repairScopes" :range-key="'name'"
				@change="repairScopeChange">
				<view class="picker">
					{{repairScopes[repairScopeIndex].name}}
				</view>
			</picker>
		</view>
		<view class="cu-form-group">
			<view class="title">手机号</view>
			<input placeholder="请输入成员手机号" v-model="phone"></input>
		</view>
		<view class="content_box">
			<button class="cu-btn bg-green margin-tb-sm lg" @click="submitOwnerMember()">提交</button>
		</view>

	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js';
	import {
		isIDCard,
		checkPhoneNumber
	} from '../../lib/java110/utils/StringUtil.js'
	const constant = context.constant;
	const factory = context.factory;

	export default {
		data() {
			return {
				phone: '',
				repairScopeIndex: '0', //默认小区
				repairScopes: [{
						id: 2,
						name: '业主成员'
					},
					{
						id: 3,
						name: '租户户主'
					},
					{
						id: 4,
						name: '租户成员'
					}
				],
				selectId: 2,
				ownerId: '',
				name: ''
			};
		},
		onLoad() {
			this.ownerId = uni.getStorageSync('commonUser').id
		},
		methods: {
			// 选中人员
			repairScopeChange: function(e) {
				this.repairScopeIndex = e.target.value //取其下标
				this.selectId = this.repairScopes[this.repairScopeIndex].id
				console.log(this.selectId);
			},
			submitOwnerMember() {
				let obj = {
					memberType: this.selectId,
					phone: this.phone,
					proprietorId: this.ownerId,
					name: this.name
				}
				uni.request({
					url: constant.url.saveOwner,
					header: context.getHeaders(),
					method: "POST",
					data: obj,
					// data:obj, //动态数据
					success: function(res) {
						console.log(res, 'dd');
						if (res.data.code != 200) {
							uni.showToast({
								title: res.data.message,
								icon: 'none',
								duration: 2000
							})
						} else {
							uni.showToast({
								title: "添加成功",
								icon: 'none',
								duration: 2000
							})
							uni.redirectTo({
								url: '/pagesA/familyList/familyList',
							});
						}
					},
					fail: function(e) {
						uni.hideLoading();
						uni.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						})
					}
				});
				// }

			},
			sexChange: function(e) {
				console.log("onConfirm", e);
				this.sex = e.detail.value;
			},
			ownerChange: function(e) {
				console.log("onConfirm", e);
				this.form_data.choiceType = e.detail.value;
			},
			addMumber() {
				for (var i = 0; i < this.form_data.length; i++) {
					var itemMember = {
						name: '',
						idCard: ''
					};
					itemMember.name = this.form_data[i].name;
					itemMember.idCard = this.form_data[i].idCard
					console.log("itemMember", itemMember)
				}
				this.form_data.push(itemMember)
				console.log(this.form_data, "添加")
			}
		}
	}
</script>
<style scoped lang="scss">
	.contenter {
		width: 100%;
		height: calc(100vh - 100rpx);
		overflow: auto;
	}

	.block__title {
		margin: 0;
		font-weight: 400;
		font-size: 14px;
		color: rgba(69, 90, 100, .6);
		padding: 40rpx 30rpx 20rpx;
	}

	.button_up_blank {
		height: 40rpx;
	}

	.content_box {
		position: fixed;
		bottom: 0rpx;
		height: 100rpx;
		width: 100%;
		display: flex;
		background-color: white;
		justify-content: center;
		align-items: center;

		button {
			width: 400rpx;
			height: 70rpx;
			margin-top: 15rpx;
			border-radius: 30rpx;
		}
	}
</style>
